gdk: Turn GdkAtom into a const char *
authorBenjamin Otte <otte@redhat.com>
Wed, 15 Nov 2017 15:57:33 +0000 (16:57 +0100)
committerBenjamin Otte <otte@redhat.com>
Wed, 15 Nov 2017 18:07:17 +0000 (19:07 +0100)
Instead of an integer, it is now a char pointer. We also use
g_intern_string() instead of doing the interning ourselves.

gdk/gdkproperty.c
gdk/gdktypes.h
gdk/wayland/gdkselection-wayland.c

index d46b9eda8e194fed8d85c5f54aa098d365ec21dc..bdd6d708c362890fb303f401d28f8c1546bad4a1 100644 (file)
  * data commonly stored in X window properties.
  */
 
-static GHashTable *names_to_atoms;
-static GPtrArray *atoms_to_names;
-
-static void
-ensure_atom_tables (void)
-{
-  if (names_to_atoms)
-    return;
-
-  names_to_atoms = g_hash_table_new (g_str_hash, g_str_equal);
-  atoms_to_names = g_ptr_array_new ();
-
-  g_ptr_array_add (atoms_to_names, NULL);
-}
-
-static GdkAtom
-intern_atom_internal (const gchar *atom_name,
-                      gboolean     allocate)
-{
-  gpointer result;
-  gchar *name;
-
-  ensure_atom_tables ();
-  
-  if (g_hash_table_lookup_extended (names_to_atoms, atom_name, NULL, &result))
-    return result;
-  
-  result = GINT_TO_POINTER (atoms_to_names->len);
-  name = allocate ? g_strdup (atom_name) : (gchar *)atom_name;
-  g_hash_table_insert (names_to_atoms, name, result);
-  g_ptr_array_add (atoms_to_names, name);
-  
-  return result;  
-}
-
 /**
  * gdk_atom_intern:
  * @atom_name: a string.
@@ -109,7 +74,7 @@ gdk_atom_intern (const gchar *atom_name,
 {
   g_return_val_if_fail (atom_name != NULL, GDK_NONE);
 
-  return intern_atom_internal (atom_name, TRUE);
+  return g_intern_string (atom_name);
 }
 
 /**
@@ -136,7 +101,7 @@ gdk_atom_intern_static_string (const gchar *atom_name)
 {
   g_return_val_if_fail (atom_name != NULL, GDK_NONE);
 
-  return intern_atom_internal (atom_name, FALSE);
+  return g_intern_static_string (atom_name);
 }
 
 /**
@@ -158,10 +123,5 @@ gdk_atom_name (GdkAtom atom)
 const gchar *
 _gdk_atom_name_const (GdkAtom atom)
 {
-  ensure_atom_tables ();
-
-  if (GPOINTER_TO_INT (atom) >= atoms_to_names->len)
-    return NULL;
-
-  return g_ptr_array_index (atoms_to_names, GPOINTER_TO_INT (atom));
+  return atom;
 }
index 0fae1ca44fd0b65c63e428a7ff657aba8f40505f..8373b321e0f7e68966565d47b0ab416a56893b09 100644 (file)
@@ -99,7 +99,7 @@ typedef cairo_rectangle_int_t         GdkRectangle;
  * An opaque type representing a string as an index into a table
  * of strings on the X server.
  */
-typedef struct _GdkAtom            *GdkAtom;
+typedef const char                   *GdkAtom;
 
 /**
  * GDK_ATOM_TO_POINTER:
@@ -107,7 +107,7 @@ typedef struct _GdkAtom            *GdkAtom;
  *
  * Converts a #GdkAtom into a pointer type.
  */
-#define GDK_ATOM_TO_POINTER(atom) (atom)
+#define GDK_ATOM_TO_POINTER(atom) ((gpointer) (atom))
 
 /**
  * GDK_POINTER_TO_ATOM:
@@ -118,15 +118,13 @@ typedef struct _GdkAtom            *GdkAtom;
  */
 #define GDK_POINTER_TO_ATOM(ptr)  ((GdkAtom)(ptr))
 
-#define _GDK_MAKE_ATOM(val) ((GdkAtom)GUINT_TO_POINTER(val))
-
 /**
  * GDK_NONE:
  *
  * A null value for #GdkAtom, used in a similar way as
  * `None` in the Xlib API.
  */
-#define GDK_NONE            ((GdkAtom) 0)
+#define GDK_NONE            NULL
 
 /* Forward declarations of commonly used types */
 typedef struct _GdkRGBA               GdkRGBA;
index b60a99ab1f2c4017131fed7a4810723798ec1c5b..6110dc0dfaeda56391cec2333ea25cb94af02013 100644 (file)
@@ -378,13 +378,13 @@ data_offer_offer (void                 *data,
 
   info = g_hash_table_lookup (selection->offers, wl_data_offer);
 
-  if (!info || g_list_find (info->targets, atom))
+  if (!info || g_list_find (info->targets, GDK_ATOM_TO_POINTER (atom)))
     return;
 
   GDK_NOTE (EVENTS,
             g_message ("data offer offer, offer %p, type = %s", wl_data_offer, type));
 
-  info->targets = g_list_prepend (info->targets, atom);
+  info->targets = g_list_prepend (info->targets, GDK_ATOM_TO_POINTER (atom));
 }
 
 static inline GdkDragAction
@@ -466,13 +466,13 @@ primary_offer_offer (void                               *data,
 
   info = g_hash_table_lookup (selection->offers, gtk_offer);
 
-  if (!info || g_list_find (info->targets, atom))
+  if (!info || g_list_find (info->targets, GDK_ATOM_TO_POINTER (atom)))
     return;
 
   GDK_NOTE (EVENTS,
             g_message ("primary offer offer, offer %p, type = %s", gtk_offer, type));
 
-  info->targets = g_list_prepend (info->targets, atom);
+  info->targets = g_list_prepend (info->targets, GDK_ATOM_TO_POINTER (atom));
 }
 
 static const struct gtk_primary_selection_offer_listener primary_offer_listener = {